<?php
    /**
     * 雅思APP接口基础类
     */
	namespace app\libs;
    use app\modules\cn\models\UserReserved;
    use yii;
    use yii\web\Controller;
    use app\modules\basic\models\Params;
    use app\modules\app\models\AppBehavior;

	class AppControl extends Controller {
		public function init() {
            $uid = Yii::$app->session->get('uid');
            $token = isset($_SERVER['HTTP_TOKEN']) && !empty($_SERVER['HTTP_TOKEN'])?$_SERVER['HTTP_TOKEN']:false;
            if ($token==false){
                $token = isset($_COOKIE['sslToken'])?$_COOKIE['sslToken']:false;
            }//兼容第一版的cookie保存token
            if($token){
                if($token == 1){
                    if($uid){
                        session_destroy();
                    }
                }else{
                    $session_token =  Yii::$app->session->get('sslToken');
                    if(!$uid || $token != $session_token){
                        if($token){
                            $date = Method::curl_post(Yii::$app->params['loginUrl'].'/cn/ssl-api/web-check',['token' => $token]);
                            $data = json_decode($date,true);
                            if($data['code'] == 1){
                                Method::confim_user($data['info']);
                                Yii::$app->session->set('sslToken',$token);
                            }
                        }
                    }
                }
            }
		}
	}
?>